package com.dodo.blog.ui.component.composite;

import com.dodo.blog.RequestCycle;
import com.dodo.blog.ui.component.container.Body;
import com.dodo.blog.ui.component.container.Footer;
import com.dodo.blog.ui.component.container.H1;
import com.dodo.blog.ui.component.container.Head;
import com.dodo.blog.ui.component.container.Header;
import com.dodo.blog.ui.component.container.Html;
import com.dodo.blog.ui.component.container.Panel;
import com.dodo.blog.ui.component.container.Section;
import com.dodo.blog.ui.component.meta.Link;
import com.dodo.blog.ui.component.meta.Script;
import com.dodo.blog.ui.page.Page;
import com.dodo.blog.ui.page.publish.About;
import com.dodo.blog.ui.page.publish.Contact;
import com.dodo.blog.ui.page.publish.Home;
import com.dodo.blog.ui.page.publish.Playground;
import com.dodo.blog.ui.page.publish.Portfolio;

import java.util.ArrayList;
import java.util.List;

/**
 * @author <a href="mailto:pohorelec@comvai.com">Jozef Pohorelec</a>
 */
public abstract class AbstractLayout
        extends Html
        implements Layout
{
    private static final long serialVersionUID = 1L;
    private static Class<? extends Page> navClasses[] = new Class[]{Home.class, Playground.class, Portfolio.class, Contact.class, About.class};

    protected Head head = new Head();
    protected H1 h1 = new H1( "" );
    protected Body body = new Body();

    protected Header header = new Header();
    protected NavigationPanel nav = new NavigationPanel( navClasses );
    protected Section section = new Section();
    protected FooterContentPanel footerContent = new FooterContentPanel( navClasses );
    protected Footer footer = new Footer();

    public Head getHead()
    {
        return head;
    }

    public Body getBody()
    {
        return body;
    }

    public Header getHeader()
    {
        return header;
    }

    public H1 getH1()
    {
        return h1;
    }

    public NavigationPanel getNav()
    {
        return nav;
    }

    public Section getSection()
    {
        return section;
    }

    @Override
    public Panel getAside()
    {
        throw new IllegalArgumentException( "Aside is not present for this layout" );
    }

    public Footer getFooter()
    {
        return footer;
    }

    public Link getStyle()
    {
        if ( RequestCycle.get().getWebApplication().isDevelopment() )
        {
            return new Link( "/styles/style.css" );
        }
        return new Link( "/styles/style.min.css" );
    }

    public List<Script> getHeaderScripts()
    {
        List<Script> scripts = new ArrayList<Script>();

        if ( RequestCycle.get().getWebApplication().isDevelopment() )
        {
            scripts.add( new Script( "/gc_lib/goog/base.js" ) );
            scripts.add( new Script( "/scripts/page.js" ) );
        }

        return scripts;
    }

    public List<Script> getBodyScripts()
    {
        List<Script> scripts = new ArrayList<Script>();
        if ( RequestCycle.get().getWebApplication().isDevelopment() )
        {
            scripts.add( new Script( "/scripts/repeater.js" ) );
            scripts.add( new Script( "/scripts/form.js" ) );
            scripts.add( new Script( "/scripts/button.js" ) );
        }
        else
        {
            scripts.add( new Script( "/scripts/script.min.js" ) );
        }

        return scripts;
    }
}